package com.agileboot.domain.performance.teaching.query;

import cn.hutool.core.util.StrUtil;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.agileboot.domain.performance.teaching.db.TeachingWorkloadEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 教学工作量查询类
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class TeachingWorkloadQuery extends AbstractPageQuery<TeachingWorkloadEntity> {

    private Long userId;
    private Integer assessmentYear;
    private Double generalCourseScore;
    private Double subjectCourseScore;
    private Double labCourseScore;
    private Long deptId;

    @Override
    public QueryWrapper<TeachingWorkloadEntity> addQueryCondition() {
        QueryWrapper<TeachingWorkloadEntity> queryWrapper = new QueryWrapper<TeachingWorkloadEntity>()
                .eq(userId != null, "user_id", userId)
                .eq(assessmentYear != null, "assessment_year", assessmentYear)
                .ge(generalCourseScore != null, "general_course_score", generalCourseScore)
                .ge(subjectCourseScore != null, "subject_course_score", subjectCourseScore)
                .ge(labCourseScore != null, "lab_course_score", labCourseScore)
                .eq(deptId != null, "dept_id", deptId);

        // 默认排序字段，如果没有指定排序字段则按create_time排序
        if (StrUtil.isEmpty(this.getOrderColumn())) {
            this.setOrderColumn("create_time");
        }
        this.setTimeRangeColumn("create_time");

        return queryWrapper;
    }
}
